#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>

namespace ghs
{
	class A
	{
	public:
		A(int a = 0, int b = 0)
			:_a(a)
			,_b(b)
		{}

		~A()
		{
			std::cout << "~A()" << std::endl;
		}
	private:
		int _a;
		int _b;
	};

	template<class T>
	class shared_ptr
	{
	public:
		shared_ptr(T* ptr)
			:_ptr(ptr)
			,_pcount(new int(1))
		{}
		//sp1(sp3)
		shared_ptr(const shared_ptr<T>& sp)
			:_ptr(sp._ptr)
			,_pcount(sp._pcount)
		{
			(*_pcount)++:
		}
		//sp1 = sp3
		shared_ptr<T>& operator=(const shared_ptr<T>& sp)
		{
			if (_ptr != sp._ptr)
			{
				this->release();

				_ptr = sp._ptr;
				_pcount = sp._pcount;

				(*_pcount)++;
			}
			return *this;
		}

		T& operator*()
		{
			return *_ptr;
		}

		T* operator->()
		{
			return _ptr;
		}
		
		int use_count()
		{
			return *_pcount;
		}

		void release()
		{
			if (--(*_pcount) == 0)
			{
				delete _ptr;
				delete _pcount;
			}
		}
		~shared_ptr()
		{
			release();
		}
	private:
		T* _ptr;
		int* _pcount;
	};
}